package com.kelvin.paopao.module.main.date.mydate.myask;

import com.kelvin.paopao.api.RetrofitService;
import com.kelvin.paopao.api.responseBean.CommonListResponse;
import com.kelvin.paopao.api.responseBean.DateListModel;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
/*
 * Created by Administrator on 2017/5/16.
 */

public class MyAskDatePresenter implements IMyAskDatePresenter {
    private MyAskDateFragment mView;

    public MyAskDatePresenter(MyAskDateFragment view) {
        this.mView = view;
    }

    @Override
    public void getData(boolean isRefresh) {
        RetrofitService.getMyAskDate(null).doOnSubscribe(new Consumer<Disposable>() {
            @Override
            public void accept(@NonNull Disposable disposable) throws Exception {
                mView.showLoading();
            }
        }).subscribeOn(AndroidSchedulers.mainThread()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<CommonListResponse<DateListModel>>() {
                    @Override
                    public void accept(@NonNull CommonListResponse dateListModelCommonListResponse) throws Exception {
                        mView.hideLoading();
                        if (dateListModelCommonListResponse.getResult() != null && dateListModelCommonListResponse.
                                getResult().size() != 0) {
                            mView.loadData(dateListModelCommonListResponse.getResult());
                        } else {
                            mView.showNodata();
                        }


                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(@NonNull Throwable throwable) throws Exception {
                        mView.hideLoading();
                    }
                }, new Action() {
                    @Override
                    public void run() throws Exception {
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void getMoreData() {

    }

    @Override
    public void cancel(String id) {

    }
}
